package com.j180.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.j180.*")
public class WebMvcConfig implements WebMvcConfigurer {

    @Bean
    public InternalResourceViewResolver getViewResolver(){
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/pages/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

    //配置 静态资源处理器 <mvc:default-servlet-handler/>
    //对应静态支援都全部放行
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }


    //要使用springMvc的文件上传功能时，需注册一个（二进制编码的解析器）
    //注意： 在注册MultipartResolver时 方法的名字必须时multipartResolver
    @Bean
    public MultipartResolver multipartResolver(){

        CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
       //设置文件的大小，不设置的话默认时没有限制
       //commonsMultipartResolver.setMaxUploadSize(1024*200);
        return commonsMultipartResolver;
    }


}
